package net.dodoman.thread;

import java.text.NumberFormat;

import net.dodoman.utils.NumberUtils;

public class Progress {

	/** 数字大点可以看出进度状态条 ,要不直接就到100%了 */
	protected static long TOTAL = 1000000000;

	public static void main(String[] args) throws InterruptedException {
		ProgressInfo pi = new ProgressInfo();
		// pi.setDaemon(true);
		for (int i = 1; i <= TOTAL; i++) {
			ProgressInfo.CURRENT = i;
			// System.out.println("for循环");
			// Thread.sleep(100);
		}
	}
}

class ProgressInfo extends Thread {

	protected static double CURRENT;

	protected ProgressInfo() {
		start();
	}

	public void run() {
		while (true) {
			NumberFormat nf = NumberFormat.getPercentInstance();
			double ds = NumberUtils.round(
					ProgressInfo.CURRENT / Progress.TOTAL, 10);
			System.out.println(nf.format(ds));
			if (ProgressInfo.CURRENT == Progress.TOTAL)
				break;
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}